package com.cy.pojo.goods.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

//描述一個数据层必须bean对象的注解
@Repository
public class DefaultGoodsDao implements GoodsDao {
    private static final Logger log= LoggerFactory.getLogger(DefaultGoodsDao.class);

    @Autowired
    private DataSource dataSource;

    @Override
    public List<Map<String, Object>> getGoods() throws SQLException {

        List<Map<String,Object>> list=new LinkedList<>();
        Connection conn= dataSource.getConnection();
        Statement stat= conn.createStatement();
        ResultSet rs= stat.executeQuery("select * from tb_goods");
        while (rs.next()){
            Map<String,Object> map=new HashMap<>();
            map.put("id", rs.getInt("id"));
            System.out.println(rs.getString("remark"));
            map.put("name",rs.getString("name"));
            map.put("remark",rs.getString("remark"));
            map.put("createdTime",rs.getString("createdTime"));
            list.add(map);
        }

        rs.close();
        stat.close();

        return list;

    }
}
